//
//  CYOrderCollectionCellSubView.m
//  CaiYun
//
//  Created by 今日信息科技 on 2017/10/16.
//  Copyright © 2017年 今日信息科技. All rights reserved.
//

#import "CYOrderCollectionCellSubView.h"
#import "CYShakeIMG.h"
@interface CYOrderCollectionCellSubView ()
@property (nonatomic, strong) CYLabel *no_record;//暂无记录
@property (nonatomic, strong) CYLabel *remind;//摇一注，2元可中20万
@property (nonatomic, strong) CYButton *orderBtn;//立即投注按钮
@property (nonatomic, strong) CYShakeIMG *shakeImg;//摇一摇图片
@property (nonatomic, strong) NSMutableArray *shakeArr;//摇一摇随机号码数组
@end
@implementation CYOrderCollectionCellSubView
- (instancetype)init{
    self = [super init];
    if (self) {
        self.no_record.hidden = self.orderBtn.hidden = self.remind.hidden = self.shakeImg.hidden = NO;
    }
    return self;
}

- (CYLabel *)no_record{
    if (!_no_record) {
        _no_record = [[CYLabel alloc]initWithText:@"您暂无记录!" size:AL(PT(28)) textcolor:RGBA(136,137,136,1)];
        [self addSubview:_no_record];
        
        [_no_record mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.top.equalTo(self).with.offset(40);
            make.size.mas_equalTo(_no_record.bounds.size);
        }];
    }
    return _no_record;
}

- (CYLabel *)remind{
    if (!_remind) {
        _remind = [[CYLabel alloc]initWithText:@"摇一注,2元可中20万元!" size:12 textcolor:RGBA(250,92,33,1)];
        [self addSubview:_remind];
        
        [_remind mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.bottom.equalTo(_orderBtn.mas_top).with.offset(- 10);
            make.size.mas_equalTo(_remind.bounds.size);
        }];
    }
    return _remind;
}

- (CYButton *)orderBtn{
    if (!_orderBtn) {
        _orderBtn = [[CYButton alloc]initWithImage:@"ljtz" cornerRadius:5.0];
        [_orderBtn addTarget:self action:@selector(actionFororderBtn) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_orderBtn];
        
        CGFloat map_height = (SCREEN_HEIGHT - TABBAR_HEIGHT - (416 / 664.0 * 300 + SCREEN_HEIGHT) * 0.5) / 2.0 - 42 / 2.0;
        [_orderBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.bottom.equalTo(self).with.offset(-20);
            make.size.mas_equalTo(CGSizeMake(AL(180), AL(42)));
        }];
    }
    
    return _orderBtn;
}

- (CYShakeIMG *)shakeImg{
    if (!_shakeImg) {
        _shakeImg  = [[CYShakeIMG alloc]initWithImageName:@"yaoyiyao"];
        [self changeShakeArray:_shakeImg.array];
        [self addSubview:_shakeImg];
        
        [_shakeImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(self);
            make.size.mas_equalTo(_shakeImg.bounds.size);
        }];
    }
    
    return _shakeImg;
}

//随机摇一摇，构建成相应数组，赋值给betting
- (void)changeShakeArray:(NSArray *)array{
    [self.shakeArr removeAllObjects];
    NSArray *weiji = @[@"万位",@"千位",@"百位",@"十位",@"个位"];
    NSMutableArray *mutableArr = [NSMutableArray array];
    for (int i = 0; i < array.count; i++) {
        [mutableArr addObject:@{weiji[i]:[NSSet setWithObject:array[i]]}];
    }
    self.shakeArr = mutableArr;
}

//摇一摇
- (void)shake{
    [_shakeImg shakeMethod];
    [self changeShakeArray:_shakeImg.array];
}

- (void)actionFororderBtn{
    if ([_delegate respondsToSelector:@selector(orderBtnDidSelected:)])
        [_delegate orderBtnDidSelected:[self.shakeArr mutableCopy]];
//    [self.shakeArr removeAllObjects];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
